﻿using System;
using System.IO;
using System.Net;
using System.Reflection;
using System.Text;
using System.Xml;

namespace PictureSplit
{
	// Token: 0x02000002 RID: 2
	internal class Update
	{
		// Token: 0x06000001 RID: 1 RVA: 0x00002050 File Offset: 0x00001050
		public bool NeedUpdate()
		{
			bool result = false;
			string remoteVersion = this.GetRemoteVersion();
			if (remoteVersion != "")
			{
				if (this.GetCurrentVersion() != this.GetRemoteVersion())
				{
					result = true;
				}
			}
			return result;
		}

		// Token: 0x06000002 RID: 2 RVA: 0x0000209C File Offset: 0x0000109C
		public string GetCurrentVersion()
		{
			return Assembly.GetExecutingAssembly().GetName().Version.ToString();
		}

		// Token: 0x06000003 RID: 3 RVA: 0x000020C4 File Offset: 0x000010C4
		private string GetRemoteVersion()
		{
			string text = "";
			WebClient webClient = new WebClient();
			try
			{
				long num = this.GetFileSize(this.URL);
				webClient.DownloadData(this.URL);
				Stream stream = webClient.OpenRead(this.URL);
				byte[] array = new byte[(int)num];
				int num2 = 0;
				while (num > 0L)
				{
					int num3 = stream.Read(array, num2, (int)num);
					if (num3 == 0)
					{
						break;
					}
					num2 += num3;
					num -= (long)num3;
				}
				string @string = Encoding.UTF8.GetString(array);
				Console.WriteLine(@string);
				XmlDocument xmlDocument = new XmlDocument();
				xmlDocument.LoadXml(@string);
				XmlNode xmlNode = xmlDocument.SelectSingleNode("descendant::NowVersion");
				text = xmlNode.InnerText;
				Console.WriteLine("Version is :{0}", text);
			}
			catch (Exception ex)
			{
				Console.WriteLine(ex.Message);
			}
			return text;
		}

		// Token: 0x06000004 RID: 4 RVA: 0x000021C8 File Offset: 0x000011C8
		private long GetFileSize(string URL)
		{
			long result = 0L;
			try
			{
				WebRequest webRequest = WebRequest.Create(URL);
				WebResponse response = webRequest.GetResponse();
				result = response.ContentLength;
				response.Close();
			}
			catch (Exception ex)
			{
				Console.WriteLine(ex.Message.ToString());
				throw ex;
			}
			return result;
		}

		// Token: 0x04000001 RID: 1
		private string URL = "http://www.game7000.com/downloads/PSUpdate.xml";
	}
}
